package main

import (
	"goweb/pkg/get"

	"github.com/gin-gonic/gin"
	_ "github.com/lib/pq"
)

// 跨域中间件
func Middle() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
		c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
		c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Token, Language, From")
		c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
		if c.Request.Method == "OPTIONS" {
			c.AbortWithStatus(204)
			return
		}
		c.Next()
	}
}

func main() {

	r := gin.Default()

	r.Use(Middle())

	get.Get_Mbti(r)
	get.Get_user(r)
	get.Get_manager(r)
	get.Register_user(r)
	get.Get_testrecord(r)
	get.Insert_record(r)
	get.Get_student(r)
	get.Get_view(r)
	get.Get_type(r)
	r.Run(":8848")
}
